﻿using System;
using System.Windows.Forms;

namespace DevTools.BinDeleter.Controls
{
    public partial class PathSelector : UserControl
    {
        public PathSelector()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            cptBrowser.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"Visual Studio 2008\Projects";
//            cptBrowser.SelectedPath = @"c:\practices";
        }

        #region Browsed event things
        public event EventHandler<BrowsedEventArgs> Browsed;

        protected virtual void OnBrowsed(BrowsedEventArgs e)
        {
            if (Browsed != null)
                Browsed(this, e);
        }

        protected virtual void OnBrowsed(string path)
        {
            if (Browsed != null)
                Browsed(this, new BrowsedEventArgs(path));
        }

        public class BrowsedEventArgs : EventArgs
        {
            private string _path;

            public string Path
            {
                get { return _path; }
                set { _path = value; }
            }

            public BrowsedEventArgs(string path)
            {
                _path = path;
            }
        }
        #endregion

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (cptBrowser.ShowDialog() == DialogResult.OK)
                OnBrowsed(cptBrowser.SelectedPath);
        }
    }
}